package edu.dgut.bbssystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import edu.dgut.bbssystem.common.PageInfo;
import edu.dgut.bbssystem.mapper.CommentMapper;
import edu.dgut.bbssystem.pojo.Comment;
import edu.dgut.bbssystem.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper mapper;

    @Override
    public int addComment(Comment comment) {
        int count = mapper.insert(comment);
        return count;
    }

    @Override
    public int deleteById(int commentId) {
        int count = mapper.deleteByPrimaryKey(commentId);
        return count;
    }

    @Override
    public PageInfo<Comment> pageQueryAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<Comment> page= mapper.getAll();
        return new PageInfo<Comment>(page);
    }
}
